<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Document</title>
  </head>
  <body>
    <script>
      var tmp = new Date();

      function f() {
        console.log(tmp);
        if (false) {
          var tmp = "hello world";
        }
      }

      f(); // undefined   为什么是undefined
    //   因为无论if里面的判断语句可不可以走进来，里面的变量都会提升，然后就近原则就是undefined

    var tmp = new Date();
    function f() {
        // var tmp
        console.log(tmp);
        if (false) {
        tmp = "hello world";
        }
      }


      var tmp = new Date();

      function f1() {
        console.log(tmp);
        if (false) {
          let tmp = "hello world";
        }
      }

      f1(); // 

      //  塊級作用域可以嵌套
      {
        let num1 = 1;
        {
          let num2 = 2;
          {
            let num3 = 3
            console.log(num1);
            console.log(num2);
          }

          console.log(num3)
        }
      }

    </script>
  </body>
</html>